import 'package:badges/badges.dart';
import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/ui_const_bean.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/work_home_bean.dart';
import '../../../r.dart';

class WorkWaitingMatterWidget extends StatelessWidget {

  final TodoItem                todoItem;
  final Function(TodoItem)      waitingMatterTap;
  final TodoModule              todoModule;
  final Function(String)        contentMatterTap;

  WorkWaitingMatterWidget(this.todoModule,this.todoItem,this.waitingMatterTap,this.contentMatterTap);

  @override
  Widget build(BuildContext context) {
    return  buildedMatterWidget();
  }

  Widget buildedMatterWidget() {
    return GestureDetector(
      child: Container(
        width: double.infinity,
        height:UIConstBean.HomeWaitMatterItemH,
        color: Colors.transparent,
        padding: const EdgeInsets.only(left: 16,right: 16,top: 5),
        child: Card(
          color: Colors.white,
          margin: const EdgeInsets.only(bottom: 0),
          elevation: 0.0,
          clipBehavior: Clip.antiAliasWithSaveLayer,
          shape: const RoundedRectangleBorder(
            side: BorderSide.none,
            borderRadius: BorderRadius.all(Radius.circular(UIConstBean.CircularRadius),
            ),
          ),

          child: Container(
            padding: EdgeInsets.only(left:12.0,top: 16.0,right: 12),
            color: Colors.white,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                InkWell(
                  onTap: (){
                    print('----查看--');
                    if(waitingMatterTap!= null){
                       waitingMatterTap(todoItem);
                    }
                  },
                  child:Container(
                    height: 27,
                    color: Colors.white,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        Text(todoModule?.title,
                          style: TextStyle(color: Color(0xff333333),
                              fontSize: 18,fontWeight: FontWeight.w600),
                        ),
                        SizedBox(width: 3,),
                        buildMessageCountWidget(),
                        const Spacer(),
                        builderLookAtWidget(),
                      ],
                    ),
                  ),
                ),

                SizedBox(height:20,),
                builderSubtitleWidget(),
                SizedBox(height:6,),
                builderContentWidget(),
              ],
            ),
          ),
        ),
      ),
      onTap: (){
      },
    );
  }
  Widget buildOneMessage(int count) {
    return Container(
      alignment: Alignment.center,
      child: Text("$count",
        style: TextStyle(
          color: Colors.white,
          fontSize: 11,
        ),
      ),
      width: 16,
      height: 16,
      decoration: BoxDecoration(
          color: Color(0xFFFF5D6A),
          borderRadius: BorderRadius.circular(8)
      ),
    );
  }
  Widget buildMore99Message() {
    return Container(
      height: 14,
      decoration: BoxDecoration(
          color: Color(0xFFFF5D6A),
          borderRadius: BorderRadius.circular(8)
      ),
      child: Text(
        " 99+ ",
        style: TextStyle(
          color: Colors.white,
          fontSize: 11,
        ),
        //textAlign: TextAlign.center,
      ),
    );
  }

  Widget buildMessageCountWidget() {
    if(todoModule == null|| (todoModule.items == null && todoModule!= null) || (todoModule!= null &&todoModule.items!= null && todoModule.items.total == 0) ) {
      return Text("");
    } else if(todoModule.items.total> 99){
      return buildMore99Message();
    } else {
      return buildOneMessage(todoModule.items.total);
    }
  }

  Widget builderLookAtWidget() {
    if(todoItem!= null) {
      return Text('查看',
          style: TextStyle(color: Color(0xff666666), fontSize:13)
      );
    }
    return Text('点击刷新',
        style: TextStyle(color: Color(0xff3dbcc6), fontSize:13)
    );
  }

  Widget builderContentWidget() {
    if(todoItem!= null) {
      return InkWell(
        onTap: (){
          print('---点击具体内容---');
          if(contentMatterTap!= null){
            contentMatterTap(todoItem.appRouteUrl);
          }
        },
        child: Container(
          height: 18,
          color: Colors.white,
          child:Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Expanded(
                child: Text(todoItem.departName,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(color: Color(0xff333333),fontSize: 14,fontWeight: FontWeight.normal),
                ),
              ),
              Container(
                width: 12,
                height: 12,
                child:Image.asset( R.imagesCommonRightArrowPng ,width: 12,height: 12,fit:BoxFit.cover,),
              ),
            ],
          ),
        ),
      );
    }

    return Container(
      color: Color(0xffebebeb),
      height: 22,
    );
  }

  Widget builderSubtitleWidget() {
     if(todoItem!= null) {
        return Text(todoItem.processStatus,style: TextStyle(color: Color(0xff333333),fontSize: 15,fontWeight: FontWeight.w500),);
     }
     return Container(
             color: Color(0xffebebeb),
             width: 40,
             height: 22,
     );
  }

}
